//添加按钮相关功能
document.querySelector("#btn_add").onclick = function () {

    let obj = document.querySelector("#select_material");
    let value = obj.options[obj.selectedIndex].value; // 选中值

    if (value == "") {
        return false;
    }

    //获取当前tableList
    let tableList = getItem("tableList");
    if (tableList == null) {
        tableList = {};
        tableList[value] = getTimestamp();
        setItem("tableList", tableList);
        addTable(value, getState(value, tableList[value]));
        layui.use("layer", function(){
            var layer = layui.layer;
            layer.msg("添加成功", {time: 1000});
        });
    }
    else {
        if (tableList[value] != null) {
            layui.use("layer", function () {
                var layer = layui.layer;
                layer.confirm("当前材料已添加，再次添加将重置计时。", { title: "警告" }, function (index) {
                    //do something
                    tableList[value] = getTimestamp();
                    setItem("tableList", tableList);
                    changeTable(value, getState(value, tableList[value]));
                    layer.close(index);
                    layui.use("layer", function(){
                        var layer = layui.layer;
                        layer.msg("添加成功", {time: 1000});
                    });
                });
            });
        }
        else {
            tableList[value] = getTimestamp();
            setItem("tableList", tableList);
            addTable(value, getState(value, tableList[value]));
            layui.use("layer", function(){
                var layer = layui.layer;
                layer.msg("添加成功", {time: 1000});
            });
        }
    }
}